package com.example.annotation;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class GetAnnotion1 {
        public static void main(String[] args) throws ClassCastException, ClassNotFoundException {
            // 通过 Class.forName 方法获取指定类的 Class 对象
            Class userClass = Class.forName("com.example.annotation.User");
            System.out.println("获取指定类中声明的所有方法");
            Method[] declaredMethods = userClass.getDeclaredMethods();
            for (Method declaredMethod : declaredMethods){
                System.out.println(declaredMethod);
            }
            System.out.println("获取指定类中声明的所有字段（属性）");
            Field[] declaredClasses = userClass.getDeclaredFields();
            for (Field declaredClass : declaredClasses){
                System.out.println(declaredClass);
            }
        }
    }


